package sisi;

import java.util.LinkedList;
import java.util.List;

import org.zkoss.zul.ListModel;
import org.zkoss.zul.SimpleListModel;

public class SimpleListModelSISI extends SimpleListModel {

	    /**
	 * 
	 */
	private static final long serialVersionUID = -1049885441649114638L;



		public SimpleListModelSISI(List data) {
	        super(data);
	    }

	public ListModel getSubModel(Object value, int nRows) {
	        final String idx = value == null ? "" : value.toString();
	        if (nRows < 0)
	            nRows = 10;
	        final LinkedList data = new LinkedList();
	        for (int i = 0; i < getSize(); i++) {
	            if (idx.equals("")
	                    || entryMatchesText(getElementAt(i).toString(), idx)) {
	                data.add(getElementAt(i));
	                if (--nRows <= 0)
	                    break; // done
	            }
	        }
	        return new SimpleListModelSISI(data);
	    }


	    public boolean entryMatchesText(String entry, String text) {
	        return entry.toLowerCase().startsWith(text.toLowerCase());
	    }
	
	
	

}
